package com.example.controller;

import com.example.domain.Blog;
import com.example.domain.property.Type;
import com.example.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;
    //分页查询
    @GetMapping("/list/{currentPage}/{PageSize}")
    @ResponseBody
    public Page<Type> index1(@PathVariable(value = "currentPage")int currentPage,@PathVariable(value = "PageSize") int PageSize){
        Page<Type> page = typeService.selectTypePage(currentPage, PageSize);
        return page;
    }
    //查询所有分类
    @GetMapping("/findAll")
    @ResponseBody
    public List<Type> index8(){
        List<Type> list = typeService.findAll();
        return list;
    }
    //新增数据
    @PostMapping("/insert")
    @ResponseBody
    public Boolean index2(@RequestBody Type type){
        boolean flag = typeService.insert(type);
        return flag;
    }
    //查询id
    @GetMapping("/selectId/{id}")
    @ResponseBody
    public Type index3(@PathVariable(value = "id") Long id){
        Type type = typeService.selectOne(id);
        return type;
    }
    //根据id更新数据
    @PutMapping("/updateRow")
    @ResponseBody
    public Boolean index4(@RequestBody Type type){
        boolean flag = typeService.updateById(type);
        return flag;
    }
    //根据id删除数据
    @DeleteMapping("/deleteRow/{id}")
    @ResponseBody
    public Boolean index5(@PathVariable(value = "id") Long id){
        boolean flag = typeService.deleteById(id);
        return flag;
    }

}
